import java.util.HashMap;
import java.util.List;
import java.util.Map;

import multiarray.MultiArray;

import coalition.CoalitionWithInfoInterface;
import population.PopulationInterface;


public class PowerExpenditureDecision {

	PopulationInterface population;
	List<CoalitionWithInfoInterface> coalitions;
	
	static final float F = 1.1f;
	static final float LAMBDA = 0.6f;
	static final float PHI = 0.2f;
	
	Map<CoalitionWithInfoInterface, Float> theta_cs;
	
	MultiArray<List<SubPopulationPowerTuple>> crossSectionPowerProfiles;
	
	public PowerExpenditureDecision(PopulationInterface population,
			List<CoalitionWithInfoInterface> coalitions,
			Map<CoalitionWithInfoInterface, Float> theta_cs
	){
		this.population = population;
		this.coalitions = coalitions;
		this.theta_cs = theta_cs;
	}
	
	public void computeUtilities(){
		
		
		
	}
	
	private float getWinnerPayoffPerAgentCrossSectionSubPopulation(
			int[] crossSectionIndices,
			CoalitionWithInfoInterface coalition,
			List<SubPopulationPowerTuple> crossSectionPowerProfile,
			int subPopulatiopnIndex
	){
		float coalitionPower = coalition.getCoalitionModulatedSize();
		float agentPower = crossSectionPowerProfile.get(subPopulatiopnIndex).getPower();
		float component1 = 1 - LAMBDA;
		component1 *= (agentPower - PHI * theta_cs.get(coalition) );
		float component2 = agentPower/coalitionPower; 
		component2 *= LAMBDA*getCoalitionExpenditure(coalitions, theta_cs);
		return component1 + component2;
	}
	
	private static float getCoalitionExpenditure(
			List<CoalitionWithInfoInterface> coalitions,
			Map<CoalitionWithInfoInterface, Float> theta_cs
			){
		float result = 0;
		for(CoalitionWithInfoInterface coalition : coalitions){
			result += coalition.getCoalitionModulatedSize() - PHI*theta_cs.get(coalition);
		}
		return result;
	}
	
	private float getLoserPayoffPerAgentCrossSectionSubPopulation(){
		return 0;
	}	
	
}

class SubPopulationPowerTuple{
	private int population;
	private float power;
	
	public SubPopulationPowerTuple(int population, float power) {
		super();
		this.population = population;
		this.power = power;
	}
	
	public int getPopulation() {
		return population;
	}
	public float getPower() {
		return power;
	}
	
	
	
}
